package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.constant.MantissaProcessingType;
import org.jsola.hr.dto.SocProgItemAddDTO;
import org.jsola.hr.dto.SocProgItemUpdateDTO;
import org.jsola.hr.entity.SocProgItemDO;
import org.jsola.hr.query.SocProgItemQuery;
import org.jsola.hr.service.ISocProgItemService;
import org.jsola.hr.vo.SocProgItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 参保方案表子项
 *
 * @author zhr
 */
@Component
public class SocProgItemTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocProgItemService socProgItemService;

    /**
     * 生成add测试数据
     * @return SocProgItemAddDTO
     */
    public SocProgItemAddDTO getSocProgItemAddDTO(){
        SocProgItemAddDTO socProgItemAddDTO = new SocProgItemAddDTO();
        socProgItemAddDTO.setProgId(getRandomValue("varchar",32));
        socProgItemAddDTO.setItemType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        socProgItemAddDTO.setItemName(getRandomValue("varchar",255));
        socProgItemAddDTO.setCardinalityDefault(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setItemMinCardinality(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setCardinalityDefaultAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setCardinalityMin(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setCardinalityMax(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setPersentCompany(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setPersentPersonal(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setAmountCompany(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setAmountPersonal(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgItemAddDTO.setMantissaProcCompany(MantissaProcessingType.NOT_PROCESSING.getValue());
        socProgItemAddDTO.setMantissaProcPersonal(MantissaProcessingType.NOT_PROCESSING.getValue());
        socProgItemAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        socProgItemAddDTO.setDefaultType(SafeKit.getInteger(getRandomValue("int",11)));
        socProgItemAddDTO.setItemRemark(getRandomValue("varchar",255));
        return socProgItemAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocProgItemUpdateDTO
     */
    public SocProgItemUpdateDTO getSocProgItemUpdateDTO(SocProgItemVO socProgItemVO){
        return socProgItemService.selectDOById(socProgItemVO.getId(), SITE_ID).to(SocProgItemUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocProgItemQuery
     */
    public SocProgItemQuery getSocProgItemQuery() {
        SocProgItemQuery socProgItemQuery = new SocProgItemQuery();
        List<SocProgItemDO> socProgItemDOList = socProgItemService.list(new SocProgItemDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socProgItemDOList)) {
            SocProgItemDO socProgItemDO = socProgItemDOList.get(0);
            socProgItemQuery = socProgItemDO.to(SocProgItemQuery.class);
            if (socProgItemDO.getCardinalityDefault() != null) {
                socProgItemQuery.setCardinalityDefaultStart(socProgItemDO.getCardinalityDefault().subtract(new BigDecimal(1)));
                socProgItemQuery.setCardinalityDefaultEnd(socProgItemDO.getCardinalityDefault().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getCardinalityMin() != null) {
                socProgItemQuery.setCardinalityMinStart(socProgItemDO.getCardinalityMin().subtract(new BigDecimal(1)));
                socProgItemQuery.setCardinalityMinEnd(socProgItemDO.getCardinalityMin().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getCardinalityMax() != null) {
                socProgItemQuery.setCardinalityMaxStart(socProgItemDO.getCardinalityMax().subtract(new BigDecimal(1)));
                socProgItemQuery.setCardinalityMaxEnd(socProgItemDO.getCardinalityMax().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getPersentCompany() != null) {
                socProgItemQuery.setPersentCompanyStart(socProgItemDO.getPersentCompany().subtract(new BigDecimal(1)));
                socProgItemQuery.setPersentCompanyEnd(socProgItemDO.getPersentCompany().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getPersentPersonal() != null) {
                socProgItemQuery.setPersentPersonalStart(socProgItemDO.getPersentPersonal().subtract(new BigDecimal(1)));
                socProgItemQuery.setPersentPersonalEnd(socProgItemDO.getPersentPersonal().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getAmountCompany() != null) {
                socProgItemQuery.setAmountCompanyStart(socProgItemDO.getAmountCompany().subtract(new BigDecimal(1)));
                socProgItemQuery.setAmountCompanyEnd(socProgItemDO.getAmountCompany().add(new BigDecimal(1)));
            }
            if (socProgItemDO.getAmountPersonal() != null) {
                socProgItemQuery.setAmountPersonalStart(socProgItemDO.getAmountPersonal().subtract(new BigDecimal(1)));
                socProgItemQuery.setAmountPersonalEnd(socProgItemDO.getAmountPersonal().add(new BigDecimal(1)));
            }
        }
        return socProgItemQuery;
    }

    /**
     * 保存示例
     * @return SocProgItemVO
     */
    public SocProgItemVO saveSocProgItemExample(){
        SocProgItemAddDTO addDTO = this.getSocProgItemAddDTO();
        SocProgItemVO socProgItemVO = socProgItemService.save(addDTO,buildTokenUser());
        return socProgItemVO;
    }


}

